package com.iplant.wms.serviceImpl;

import com.iplant.base.po.OutResult;
import com.iplant.base.po.Pagination;
import com.iplant.base.po.ServiceResult;
import com.iplant.base.po.enums.ExceptionTypes;
import com.iplant.base.utils.bar.QRCodeUtil;
import com.iplant.base.utils.general.Configuration;
import com.iplant.base.utils.general.StringUtils;
import com.iplant.basic.service.po.bms.BMSEmployee;
import com.iplant.basic.utils.Constants;
import com.iplant.wms.service.SMSSService;
import com.iplant.wms.service.po.batch.MSSBatchProp;
import com.iplant.wms.service.po.batch.MSSBatchRange;
import com.iplant.wms.service.po.batch.MSSBatchRule;
import com.iplant.wms.service.po.mss.*;
import com.iplant.wms.service.po.pkg.*;
import com.iplant.wms.serviceImpl.dao.batch.MSSBatchPropDAO;
import com.iplant.wms.serviceImpl.dao.batch.MSSBatchRangeDAO;
import com.iplant.wms.serviceImpl.dao.batch.MSSBatchRuleDAO;
import com.iplant.wms.serviceImpl.dao.mss.*;
import com.iplant.wms.serviceImpl.dao.pkg.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

@Service
public class SMSSServiceImpl implements SMSSService {

    public SMSSServiceImpl() {
        // TODO Auto-generated constructor stub
    }

    private static final Logger logger = LoggerFactory.getLogger(SMSSServiceImpl.class);

    private static SMSSService Instance = null;

    public static SMSSService getInstance() {
        if (Instance == null) {
            Instance = new SMSSServiceImpl();
        }

        return Instance;
    }



    // 单位换算

    @Override
    public ServiceResult<Integer> MSS_UpdateMeasureUnit(BMSEmployee wLoginUser, MSSMeasureUnit wMeasureUnit) {

        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            MSSMeasureUnitDAO.getInstance().MSS_UpdateMeasureUnit(wLoginUser, wMeasureUnit, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<Integer> MSS_DeleteMeasureUnit(BMSEmployee wLoginUser, MSSMeasureUnit wMeasureUnit) {
        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            MSSMeasureUnitDAO.getInstance().DeletePO(wLoginUser, wMeasureUnit, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<Integer> MSS_ActiveMeasureUnit(
            BMSEmployee wLoginUser, MSSMeasureUnit wMeasureUnit, int wActive) {
        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            MSSMeasureUnitDAO.getInstance().MSS_ActiveMeasureUnit(wLoginUser, wMeasureUnit, wActive, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<MSSMeasureUnit> MSS_QueryMeasureUnit(
            BMSEmployee wLoginUser, int wMeasureUnitID, int wSourceUnitID) {

        ServiceResult<MSSMeasureUnit> wResult = new ServiceResult<MSSMeasureUnit>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            wResult.Result = MSSMeasureUnitDAO.getInstance().MSS_QueryMeasureUnit(wLoginUser, wMeasureUnitID,
                    wSourceUnitID, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<List<MSSMeasureUnit>> MSS_QueryMeasureUnitList(
            BMSEmployee wLoginUser, List<Integer> wMeasureUnitID, List<Integer> wSourceUnitID, int wActive,
            Pagination wPagination) {
        ServiceResult<List<MSSMeasureUnit>> wResult = new ServiceResult<List<MSSMeasureUnit>>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            wResult.Result = MSSMeasureUnitDAO.getInstance().MSS_QueryMeasureUnitList(wLoginUser, wMeasureUnitID,
                    wSourceUnitID, wActive, wPagination, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }


    //批次管理




    //批次模板


    @Override
    public ServiceResult<Integer> MSS_DeleteBatchRule(BMSEmployee wLoginUser, MSSBatchRule wBatchRule) {

        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            MSSBatchRuleDAO.getInstance().MSS_DeleteBatchRule(wLoginUser, wBatchRule, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }



    @Override
    public ServiceResult<List<MSSBatchRule>> MSS_QueryBatchRuleList(
            BMSEmployee wLoginUser, String wName, int wActive, Pagination wPagination) {
        ServiceResult<List<MSSBatchRule>> wResult = new ServiceResult<List<MSSBatchRule>>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            wResult.Result = MSSBatchRuleDAO.getInstance().MSS_QueryBatchRuleList(
                    wLoginUser, wName, wActive, wPagination, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    //批次属性
    @Override
    public ServiceResult<Integer> MSS_UpdateBatchProp(BMSEmployee wLoginUser, MSSBatchProp wBatchProp) {
        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            MSSBatchPropDAO.getInstance().UpdatePo(wLoginUser, wBatchProp, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<List<MSSBatchProp>> MSS_QueryBatchPropList(
            BMSEmployee wLoginUser, int wRuleID, String wRuleCode) {
        ServiceResult<List<MSSBatchProp>> wResult = new ServiceResult<List<MSSBatchProp>>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            wResult.Result = MSSBatchPropDAO.getInstance().MSS_QueryBatchPropList(
                    wLoginUser, wRuleID, wRuleCode, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }



    @Override
    public ServiceResult<MSSBatchRange> MSS_QueryBatchRange(
            BMSEmployee wLoginUser, int wCustomerID, String wMaterialNo) {
        ServiceResult<MSSBatchRange> wResult = new ServiceResult<>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            wResult.Result = MSSBatchRangeDAO.getInstance().MSS_QueryBatchRange(
                    wLoginUser, wCustomerID, wMaterialNo, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }


    @Override
    public ServiceResult<List<MSSBatchRange>> MSS_QueryBatchRangeList(
            BMSEmployee wLoginUser, int wCustomerID,
            String wMaterialGroupFullName, int wMaterialID,
            Pagination wPagination) {
        ServiceResult<List<MSSBatchRange>> wResult = new ServiceResult<List<MSSBatchRange>>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            wResult.Result = MSSBatchRangeDAO.getInstance().MSS_QueryBatchRangeList(
                    wLoginUser, wCustomerID,  wMaterialGroupFullName, wMaterialID,
                    wPagination, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }


    //周转规则管理


    //周转规则
    @Override
    public ServiceResult<Integer> MSS_UpdateTransferRule(BMSEmployee wLoginUser, MSSTransferRule wTransferRule) {

        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            MSSTransferRuleDAO.getInstance().MSS_UpdateTransferRule(wLoginUser, wTransferRule, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<Integer> MSS_DeleteTransferRule(BMSEmployee wLoginUser, MSSTransferRule wTransferRule) {

        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            MSSTransferRuleDAO.getInstance().MSS_DeleteTransferRule(wLoginUser, wTransferRule, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<Integer> MSS_ActiveTransferRule(
            BMSEmployee wLoginUser, MSSTransferRule wTransferRule, int wActive) {

        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            MSSTransferRuleDAO.getInstance().MSS_ActiveTransferRule(wLoginUser, wTransferRule, wActive, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<MSSTransferRule> MSS_QueryTransferRule(BMSEmployee wLoginUser, int wID, String wCode) {
        ServiceResult<MSSTransferRule> wResult = new ServiceResult<MSSTransferRule>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            wResult.Result = MSSTransferRuleDAO.getInstance().MSS_QueryTransferRule(wLoginUser, wID, wCode, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<List<MSSTransferRule>> MSS_QueryTransferRuleList(
            BMSEmployee wLoginUser, String wName, int wBatchRuleID, String wBatchRuleCode, int wActive,
            Pagination wPagination) {
        ServiceResult<List<MSSTransferRule>> wResult = new ServiceResult<List<MSSTransferRule>>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            wResult.Result = MSSTransferRuleDAO.getInstance().MSS_QueryTransferRuleList(
                    wLoginUser, wName, wBatchRuleID, wBatchRuleCode, wActive, wPagination, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    //批次属性
    @Override
    public ServiceResult<Integer> MSS_UpdateTransferProp(BMSEmployee wLoginUser, MSSTransferProp wTransferProp) {
        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            MSSTransferPropDAO.getInstance().MSS_UpdateTransferProp(wLoginUser, wTransferProp, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<List<MSSTransferProp>> MSS_QueryTransferPropList(
            BMSEmployee wLoginUser, int wRuleID, String wRuleCode, int wBatchRuleID, String wBatchRuleCode,
            int wBatchPropID, String wBatchPropCode, String wName, String wCode, List<Integer> wActive,
            Pagination wPagination) {
        ServiceResult<List<MSSTransferProp>> wResult = new ServiceResult<List<MSSTransferProp>>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            wResult.Result = MSSTransferPropDAO.getInstance().MSS_QueryTransferPropList(
                    wLoginUser, wRuleID, wRuleCode, wBatchRuleID, wBatchRuleCode, wBatchPropID, wBatchPropCode, wName,
                    wCode, wActive, wPagination, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<Integer> MSS_ActiveTransferProp(
            BMSEmployee wLoginUser, MSSTransferProp wTransferProp, int wActive) {
        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            MSSTransferPropDAO.getInstance().MSS_ActiveTransferProp(wLoginUser, wTransferProp, wActive, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }


    //批次范围

    @Override
    public ServiceResult<Integer> MSS_UpdateTransferRange(BMSEmployee wLoginUser, MSSTransferRange wTransferRange) {

        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);


            MSSTransferRangeDAO.getInstance().MSS_UpdateTransferRange(wLoginUser, wTransferRange, wErrorCode);


            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<Integer> MSS_DeleteTransferRange(BMSEmployee wLoginUser, MSSTransferRange wTransferRange) {

        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);


            MSSTransferRangeDAO.getInstance().DeletePO(wLoginUser, wTransferRange, wErrorCode);


            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<MSSTransferRange> MSS_QueryTransferRange(
            BMSEmployee wLoginUser, int wCustomerID, String wMaterialNo) {
        ServiceResult<MSSTransferRange> wResult = new ServiceResult<>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            wResult.Result = MSSTransferRangeDAO.getInstance().MSS_QueryTransferRange(
                    wLoginUser, wCustomerID, wMaterialNo, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }


    @Override
    public ServiceResult<List<MSSTransferRange>> MSS_QueryTransferRangeList(
            BMSEmployee wLoginUser, int wCustomerID, List<Integer> wCustomerIDList, int wMaterialGroupID,
            String wMaterialGroupFullName, int wMaterialID, List<String> wMaterialCode, String wMaterialLike,
            Pagination wPagination) {
        ServiceResult<List<MSSTransferRange>> wResult = new ServiceResult<List<MSSTransferRange>>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            wResult.Result = MSSTransferRangeDAO.getInstance().MSS_QueryTransferRangeList(
                    wLoginUser, wCustomerID, wCustomerIDList, wMaterialGroupID, wMaterialGroupFullName, wMaterialID,
                    wMaterialCode, wMaterialLike, wPagination, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }


    //包装管理


    //包装模板
    @Override
    public ServiceResult<Integer> MSS_UpdatePackageRule(BMSEmployee wLoginUser, MSSPackageRule wPackageRule) {

        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            MSSPackageRuleDAO.getInstance().MSS_UpdatePackageRule(wLoginUser, wPackageRule, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<Integer> MSS_DeletePackageRule(BMSEmployee wLoginUser, MSSPackageRule wPackageRule) {

        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            MSSPackageRuleDAO.getInstance().MSS_DeletePackageRule(wLoginUser, wPackageRule, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<Integer> MSS_ActivePackageRule(
            BMSEmployee wLoginUser, MSSPackageRule wPackageRule, int wActive) {

        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            MSSPackageRuleDAO.getInstance().MSS_ActivePackageRule(wLoginUser, wPackageRule, wActive, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<MSSPackageRule> MSS_QueryPackageRule(BMSEmployee wLoginUser, int wID, String wCode) {
        ServiceResult<MSSPackageRule> wResult = new ServiceResult<MSSPackageRule>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            wResult.Result = MSSPackageRuleDAO.getInstance().MSS_QueryPackageRule(wLoginUser, wID, wCode, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<List<MSSPackageRule>> MSS_QueryPackageRuleList(
            BMSEmployee wLoginUser, String wName, int wActive, Pagination wPagination) {
        ServiceResult<List<MSSPackageRule>> wResult = new ServiceResult<List<MSSPackageRule>>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            wResult.Result = MSSPackageRuleDAO.getInstance().MSS_QueryPackageRuleList(
                    wLoginUser, wName, wActive, wPagination, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    //包装属性
    @Override
    public ServiceResult<Integer> MSS_UpdatePackageProp(BMSEmployee wLoginUser, MSSPackageProp wPackageProp) {
        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            MSSPackagePropDAO.getInstance().MSS_UpdatePackageProp(wLoginUser, wPackageProp, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<List<MSSPackageProp>> MSS_QueryPackagePropList(
            BMSEmployee wLoginUser, int wRuleID, String wRuleCode) {
        ServiceResult<List<MSSPackageProp>> wResult = new ServiceResult<List<MSSPackageProp>>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            wResult.Result = MSSPackagePropDAO.getInstance().MSS_QueryPackagePropList(
                    wLoginUser, wRuleID, wRuleCode, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<Integer> MSS_ActivePackageProp(
            BMSEmployee wLoginUser, MSSPackageProp wPackageProp, int wActive) {
        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            MSSPackagePropDAO.getInstance().MSS_ActivePackageProp(wLoginUser, wPackageProp, wActive, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<List<MSSPackageProp>> MSS_QueryPackagePropList(
            BMSEmployee wLoginUser, int wRuleID, String wRuleCode, String wName, String wCode, List<Integer> wActive,
            Pagination wPagination) {
        ServiceResult<List<MSSPackageProp>> wResult = new ServiceResult<List<MSSPackageProp>>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            wResult.Result = MSSPackagePropDAO.getInstance().MSS_QueryPackagePropList(wLoginUser, wRuleID, wRuleCode,
                    wName, wCode, wActive, wPagination, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }
    //包装范围

    @Override
    public ServiceResult<Integer> MSS_UpdatePackageRange(BMSEmployee wLoginUser, MSSPackageRange wPackageRange) {

        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);


            MSSPackageRangeDAO.getInstance().MSS_UpdatePackageRange(wLoginUser, wPackageRange, wErrorCode);


            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<Integer> MSS_DeletePackageRange(BMSEmployee wLoginUser, MSSPackageRange wPackageRange) {

        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);


            MSSPackageRangeDAO.getInstance().DeletePO(wLoginUser, wPackageRange, wErrorCode);


            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }


    @Override
    public ServiceResult<List<MSSPackageRange>> MSS_QueryPackageRangeList(
            BMSEmployee wLoginUser, int wCustomerID, List<Integer> wCustomerIDList, int wMaterialGroupID,
            String wMaterialGroupFullName, int wMaterialID, List<String> wMaterialCode, String wMaterialLike,
            Pagination wPagination) {
        ServiceResult<List<MSSPackageRange>> wResult = new ServiceResult<List<MSSPackageRange>>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            wResult.Result = MSSPackageRangeDAO.getInstance().MSS_QueryPackageRangeList(wLoginUser, wCustomerID,
                    wCustomerIDList, wMaterialGroupID, wMaterialGroupFullName, wMaterialID, wMaterialCode,
                    wMaterialLike, wPagination, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }


    @Override
    public ServiceResult<MSSPackageRange> MSS_QueryPackageRange(
            BMSEmployee wLoginUser, int wCustomerID, String wMaterialNo) {
        ServiceResult<MSSPackageRange> wResult = new ServiceResult<>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            wResult.Result = MSSPackageRangeDAO.getInstance().MSS_QueryPackageRange(
                    wLoginUser, wCustomerID, wMaterialNo, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }





    @Override
    public ServiceResult<Integer> MSS_UpdateMaterialStation(
            BMSEmployee wLoginUser, MSSMaterialStation wMaterialStation) {
        ServiceResult<Integer> wResult = new ServiceResult<Integer>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>();
            wErrorCode.set(0);
            MSSMaterialStationDAO.getInstance().UpdatePo(wLoginUser, wMaterialStation, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            wResult.FaultCode += e.toString();
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<Integer> MSS_UpdateMaterialStationList(
            BMSEmployee wLoginUser, List<MSSMaterialStation> wMaterialStation) {
        ServiceResult<Integer> wResult = new ServiceResult<Integer>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>();
            wErrorCode.set(0);
            MSSMaterialStationDAO.getInstance().UpdatePoList(wLoginUser, wMaterialStation, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            wResult.FaultCode += e.toString();
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<Integer> MSS_DeleteMaterialStation(
            BMSEmployee wLoginUser, MSSMaterialStation wMaterialStation) {
        ServiceResult<Integer> wResult = new ServiceResult<Integer>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>();
            MSSMaterialStationDAO.getInstance().DeletePO(wLoginUser, wMaterialStation, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            wResult.FaultCode += e.toString();
            logger.error(e.toString());
        }
        return wResult;
    }

    // 容器类型

    @Override
    public ServiceResult<Integer> MSS_UpdateContainerType(BMSEmployee wLoginUser, MSSContainerType wContainerType) {
        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            MSSContainerTypeDAO.getInstance().MSS_UpdateContainerType(wLoginUser, wContainerType, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<Integer> MSS_DeleteContainerType(BMSEmployee wLoginUser, MSSContainerType wContainerType) {
        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            MSSContainerTypeDAO.getInstance().DeletePO(wLoginUser, wContainerType, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<Integer> MSS_ActiveContainerType(
            BMSEmployee wLoginUser, MSSContainerType wContainerType, int wActive) {
        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            MSSContainerTypeDAO.getInstance().MSS_ActiveContainerType(wLoginUser, wContainerType, wActive, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<MSSContainerType> MSS_QueryContainerType(BMSEmployee wLoginUser, int wID, String wCode) {
        ServiceResult<MSSContainerType> wResult = new ServiceResult<MSSContainerType>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            wResult.Result = MSSContainerTypeDAO.getInstance().MSS_QueryContainerType(wLoginUser, wID, wCode,
                    wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<List<MSSContainerType>> MSS_QueryContainerTypeList(
            BMSEmployee wLoginUser, String wName, int wActive, Pagination wPagination) {
        ServiceResult<List<MSSContainerType>> wResult = new ServiceResult<List<MSSContainerType>>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            wResult.Result = MSSContainerTypeDAO.getInstance().MSS_QueryContainerTypeList(wLoginUser, wName, wActive,
                    wPagination, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    // 容器
    @Override
    public ServiceResult<Integer> MSS_UpdateContainer(BMSEmployee wLoginUser, MSSContainer wContainer) {
        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            MSSContainerDAO.getInstance().MSS_UpdateContainer(wLoginUser, wContainer, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<Integer> MSS_DeleteContainer(BMSEmployee wLoginUser, MSSContainer wContainer) {
        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            MSSContainerDAO.getInstance().DeletePO(wLoginUser, wContainer, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<Integer> MSS_ActiveContainer(BMSEmployee wLoginUser, MSSContainer wContainer, int wActive) {
        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            MSSContainerDAO.getInstance().MSS_ActiveContainer(wLoginUser, wContainer, wActive, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<MSSContainer> MSS_QueryContainer(BMSEmployee wLoginUser, int wID, String wCode) {
        ServiceResult<MSSContainer> wResult = new ServiceResult<MSSContainer>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            wResult.Result = MSSContainerDAO.getInstance().MSS_QueryContainer(wLoginUser, wID, wCode, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<List<MSSContainer>> MSS_QueryContainerList(
            BMSEmployee wLoginUser, int wTypeID, String wName, String wTypeCode, String wTypeName, int wActive,
            Pagination wPagination) {
        ServiceResult<List<MSSContainer>> wResult = new ServiceResult<List<MSSContainer>>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            wResult.Result = MSSContainerDAO.getInstance().MSS_QueryContainerList(wLoginUser, wTypeID, wName, wTypeCode,
                    wTypeName, wActive, wPagination, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }


    @Override
    public ServiceResult<List<String>> WMS_CreateQRCodeList(BMSEmployee wLoginUser, List<String> wStringList) {

        ServiceResult<List<String>> wResult = new ServiceResult<>();

        try {
            wResult.Result = new ArrayList<>();

            for (String wItem : wStringList) {
                String wQRCode = getQRCodeString(wLoginUser, wItem);
                wResult.Result.add(wQRCode);
            }
        } catch (Exception ex) {
            wResult.FaultCode += ex.toString();
            logger.error(ex.toString());
        }

        return wResult;
    }

    private String getQRCodeString(BMSEmployee wLoginUser, String wText) {
        String wResult = "";
        try {
            // ②嵌入二维码的图片路径
            String imgPath = "";
            // ③文件名称
            String wFileName = UUID.randomUUID().toString().replaceAll("-", "");
            // ④生成的二维码的路径及名称
            String wDirePath = StringUtils.Format("{0}export/{1}.jpg",
                    Constants.getStaticPath(), wFileName);
            File wDirFile = new File(wDirePath);
            if (!wDirFile.exists()) {
                wDirFile.mkdirs();
            }
            // ⑥生成二维码
            QRCodeUtil.encode(wText, imgPath, wDirePath, true);
            // ⑦返回路径
            wResult = StringUtils.Format("/{0}/export/{1}.jpg",
                    Configuration.readConfigString("project.name", "application"), wFileName);
        } catch (Exception ex) {
            logger.error(ex.toString());
        }

        return wResult;
    }

}
